<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>联系人编辑</title>
<LINK href="<%=basePath%>/css/top.css" type=text/css rel=stylesheet />
<LINK href="<%=basePath%>/css/main.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
function method2(tableid) //读取表格中每个单元到EXCEL中 
{  

    var curTbl = document.getElementById(tableid); 
    
      try { 
            var oXL = new ActiveXObject("Excel.Application"); 
      } 
      catch(e) 
      { 
        alert( "您必须安装Excel2000或以上，同时浏览器须使用“ActiveX 控件”，您的浏览器须允许执行控件。请选择Internet设置--安全选项--本地Intranet--改区域的安全级别设置为低，才能导出到Excel！"); 
        
        window.location.reload(); 
        return ""; 
      } 
    
    //创建AX对象excel 
    var oWB = oXL.Workbooks.Add(); 
    //获取workbook对象 
    var oSheet = oWB.ActiveSheet; 
    //激活当前sheet 
    var Lenr = curTbl.rows.length; 
    //取得表格行数 
    for (i = 0; i < Lenr; i++) 
    { 
        var Lenc = curTbl.rows(i).cells.length; 
        

        //<!--设置显示字符而不是数字--> 
          
        oSheet.Columns(6).NumberFormatLocal="@" 
        oSheet.Columns(5).NumberFormatLocal="@"; 
        oSheet.Columns(8).NumberFormatLocal="@"; 
        //取得每行的列数 
        for (j = 0; j < Lenc; j++) 
        { 
            oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText; 
            //赋值 
        } 
    } 
    oXL.Selection.HorizontalAlignment = -4108;        //'xlHAlignCenter  横向居中 
    //oXL.Range("a1:b1:c1:d1:f1:g1:h1:i1:j1:k1").MergeCells = true;//合并 
    //oXL.Range("a1:b1").select;//选中 
    //oXL.Selection.VerticalAlignment = -4108;          //'xlVAlignCenter  竖向居中 
    oSheet.Columns.AutoFit; //自动适应大小 
    //设置excel可见属性 
    oXL.Visible = true; 
    oXL.UserControl = true;  //excel交由用户控制 

} 




 
      function saveToExcel() 
   { 
     var oXL = new ActiveXObject("Excel.Application"); 
     var oWB = oXL.Workbooks.Add(); 
     var oSheet = oWB.ActiveSheet; 
     var sel=document.body.createTextRange(); 
     sel.moveToElementText(tableId); 
     sel.select(); 
     sel.execCommand("Copy"); 
     oSheet.Paste(); 
     oXL.Visible = true; 
   } 

</script>
</head>

<BODY topmargin="5">
<form name="Form1" method="get" action="ContactsServlet" id="Form1">
<div><input type="hidden" name="contacts" id="__VIEWSTATE"
	value="edit" /></div>

<table border="0" width="100%" cellspacing="0" cellpadding="3"
	class="small">
	<tr>
		<td class="Big"><img src="<%=basePath%>/img/office/address.gif"
			align="absMiddle"><span class="big3">打印名片</span></td>
	</tr>
</table>
<table id="mytable" border="0" cellspacing="1" width="95%" class="small"
	bgcolor="#000000" cellpadding="3">
	<thead class="TableHeader">
		<td nowrap align="center">姓名</td>
		<td nowrap align="center">性别</td>
		<td nowrap align="center">单位电话</td>
		<td nowrap align="center">家庭电话</td>
		<td nowrap align="center">手机 <a href="javascript:send_mobile()"></a></td>
		<td nowrap align="center">电子邮件</td>
		<td nowrap align="center">家庭地址</td>
		<td nowrap align="center">生日</td>
		<td nowrap align="center">职务</td>
		<td nowrap align="center">配偶</td>
		<td nowrap align="center">MSN</td>
		<td nowrap align="center">备注</td>
		<td nowrap align="center">单位地址</td>
		<td nowrap align="center">单位名字</td>

	</thead>
	<c:forEach items="${contactsGroup}" var="a">
		<tr class="TableLine1">
			<td nowrap align="center"><c:out value="${a.personName}"></c:out>
			<a href="javascript:add_detail('1');"></a></td>
			<td nowrap align="center"><c:out value="${a.personSex}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.unitPhone}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.familyPhone}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.personMobile}"></c:out><a
				target="_blank" title="发送手机短信" href=""></a></td>
			<td nowrap align="center"><c:out value="${a.personEmail}"></c:out><a
				href="mailto:"></a></td>
			<td nowrap align="center"><c:out value="${a.familyAddress}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.personBir}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.personDuty}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.personMate}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.personMSN}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.personRemark}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.unitAddress}"></c:out></td>
			<td nowrap align="center"><c:out value="${a.unitName}"></c:out></td>

		</tr>

	</c:forEach>

</table>
<table class="small" align="center">
	<tr class="TableLine1">
		<td align="center" nowrap><input class=BigButton type="button"
			value="生成表" name="mybutton" onclick="method2(mytable)"></td>
	</tr>
</table>


</form>
</BODY>
</html>